import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.net.URLEncoder;

@WebServlet("/c")
public class ServletC extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie("username","zhangsan");
        cookie.setMaxAge(1000);
        String username = "张三";
        String encodeUsername = URLEncoder.encode(username, "UTF-8");
        Cookie cookie2 = new Cookie("uname",encodeUsername);
        cookie2.setAttribute("zs","aaa");
        response.addCookie(cookie2);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}